#include "Theme.h"
#include "BaseInc.h"
#include "Utility.h"
#include "tinyxml/tinyxml.h"
namespace Theme
{
	extern tstring BUTTON_BORDER_COLOR = BORDER_COLOR;
	extern tstring BUTTON_BACK_COLOR = _T("#FFEF3300");
	extern tstring BUTTON_FORE_COLOR = _T("#FFEE4400");
	extern tstring BUTTON_HOVER_COLOR = _T("#FF0E3F22");
	extern tstring BUTTON_PRESS_COLOR = _T("3F0E3F22");
	extern tstring LABEL_BACK_COLOR = _T("#FF00FF00");
	extern tstring LABEL_TEXT_COLOR = _T("#FFFFFFFF");
	extern tstring PROGRESS_CONTAINER_COLOR = _T("#FF00FF00");
	extern tstring PROGRESS_CONTAINER_BORDER_COLOR = _T("#FF00FF00");
	extern tstring PROGRESS_THUMB_COLOR = _T("#FF0F0F00");
	extern tstring PROGRESS_THUMB_BORDER_COLOR = BORDER_COLOR;
	extern tstring PROGRESS_THUMB_HOVER_COLOR = _T("#FF0F0FF0");
	extern tstring RELATIVE_BOX_BACK_COLOR = _T("#FF0F0F00");
	extern tstring RELATIVE_BOX_BORDER_COLOR = _T("#FF0F0F00");

	bool CustomTheme::ParseFromXml(const char* file)
	{
		TiXmlDocument doc;
		if (!doc.LoadFile(file)) return false;

		::TiXmlElement* root = doc.RootElement();
		::TiXmlElement* clr = root->FirstChildElement("Color");

		while (clr)
		{
			//if(clr->Attribute())
			::TiXmlAttribute* attr = clr->FirstAttribute();
			if (SetColor("BACK_COLOR", clr)) {}
			else if (SetColor("FORE_COLOR", clr)) {}
			else if (SetColor("HOVER_COLOR", clr)) {}
			else if (SetColor("PRESS_COLOR", clr)) {}
			else if (SetColor("BORDER_COLOR", clr)) {}
			else if (SetColor("THUMB_COLOR", clr)) {}
			else if (SetColor("THUMB_BORDER_COLOR", clr)) {}
			else if (SetColor("THUMB_HOVER_COLOR", clr)) {}

			clr = clr->NextSiblingElement("Color");
		}
		return true;
	}

	bool CustomTheme::SetColor(std::string key, ::TiXmlElement* clr)
	{
		std::string s_clr_name = clr->Attribute("name");
		//if (strcmp(s_clr_name.data(), key.data()) == 0)
		if (s_clr_name == key)
		{
			mp_clr[key] = clr->Attribute("value");
			return true;
		}
		return false;
	}

}